<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="物料名称" prop="erpName">
        <el-input
          v-model="queryParams.erpName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规格" prop="chinaName">
        <el-input
          v-model="queryParams.chinaName"
          placeholder="请输入规格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编码" prop="partId">
        <el-input
          v-model="queryParams.partId"
          placeholder="请输入物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="期间" prop="periodDate">
        <el-date-picker 
          :clearable="false"
          v-model="queryParams.periodDate"
          type="month"
          value-format="yyyy-MM"
          placeholder="请选择期间"
          >
        </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="刷新数据" prop="flushi">
        <el-select v-model="queryParams.flushi" placeholder="是否刷新数据" clearable>
          <el-option
          v-for="dict in dict.type.sys_yes_no"
          :key="dict.value"
          :label="dict.label"
          :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="消耗数量" prop="mateNum">
        <el-input
          v-model="queryParams.mateNum"
          placeholder="请输入消耗数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="销售数量" prop="proNum">
        <el-input
          v-model="queryParams.proNum"
          placeholder="请输入销售数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合计数量" prop="totalNum">
        <el-input
          v-model="queryParams.totalNum"
          placeholder="请输入合计数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="别名" prop="asName">
        <el-input
          v-model="queryParams.asName"
          placeholder="请输入别名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="bom名称" prop="bomName">
        <el-input
          v-model="queryParams.bomName"
          placeholder="请输入bom名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="bom版本" prop="bomVar">
        <el-input
          v-model="queryParams.bomVar"
          placeholder="请输入bom版本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="父项编码" prop="parentId">
        <el-input
          v-model="queryParams.parentId"
          placeholder="请输入父项编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="父项目版本" prop="fatherPartvar">
        <el-input
          v-model="queryParams.fatherPartvar"
          placeholder="请输入父项目版本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      
      <!-- <el-form-item label="期间" prop="moth">
        <el-input
          v-model="queryParams.moth"
          placeholder="请输入期间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="层次号" prop="assembLelevel">
        <el-input
          v-model="queryParams.assembLelevel"
          placeholder="请输入层次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料版本" prop="partVar">
        <el-input
          v-model="queryParams.partVar"
          placeholder="请输入物料版本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数量" prop="counts">
        <el-input
          v-model="queryParams.counts"
          placeholder="请输入数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年度" prop="year">
        <el-input
          v-model="queryParams.year"
          placeholder="请输入年度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市场价格" prop="marketPrice">
        <el-input
          v-model="queryParams.marketPrice"
          placeholder="请输入市场价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="材料价格" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入材料价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="含税单价" prop="taxPrice">
        <el-input
          v-model="queryParams.taxPrice"
          placeholder="请输入含税单价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市场价格(含税)" prop="marktaxPrice">
        <el-input
          v-model="queryParams.marktaxPrice"
          placeholder="请输入市场价格(含税)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成品价格" prop="productPrice">
        <el-input
          v-model="queryParams.productPrice"
          placeholder="请输入成品价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="直接人工" prop="workFee">
        <el-input
          v-model="queryParams.workFee"
          placeholder="请输入直接人工"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="天然气" prop="gasFee">
        <el-input
          v-model="queryParams.gasFee"
          placeholder="请输入天然气"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电费" prop="elecFee">
        <el-input
          v-model="queryParams.elecFee"
          placeholder="请输入电费"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制造费用" prop="makeFee">
        <el-input
          v-model="queryParams.makeFee"
          placeholder="请输入制造费用"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标准合计" prop="stTotalFee">
        <el-input
          v-model="queryParams.stTotalFee"
          placeholder="请输入标准合计"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合计" prop="totalFee">
        <el-input
          v-model="queryParams.totalFee"
          placeholder="请输入合计"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毛利率" prop="grossProfitRate">
        <el-input
          v-model="queryParams.grossProfitRate"
          placeholder="请输入毛利率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标准销售价格" prop="stSalePrice">
        <el-input
          v-model="queryParams.stSalePrice"
          placeholder="请输入标准销售价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售价格" prop="salePrice">
        <el-input
          v-model="queryParams.salePrice"
          placeholder="请输入销售价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时间戳" prop="nodeTimesTamp">
        <el-date-picker clearable
          v-model="queryParams.nodeTimesTamp"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择时间戳">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="价格时间" prop="priceTime">
        <el-date-picker clearable
          v-model="queryParams.priceTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择价格时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="备注" prop="marks">
        <el-input
          v-model="queryParams.marks"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基期" prop="partDate">
        <el-date-picker clearable
          v-model="queryParams.partDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择基期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="root值" prop="rootCode">
        <el-input
          v-model="queryParams.rootCode"
          placeholder="请输入root值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="序列号" prop="seqnum">
        <el-input
          v-model="queryParams.seqnum"
          placeholder="请输入序列号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:count:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:count:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:count:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:count:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="countList" >
      <el-table-column
        type="index"
        width="90"
        align="center"
        :index="indexMethod"
        label="序号">
      </el-table-column>
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <!-- <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="类型编码0-原料,1-产品,2-半成品" align="center" prop="type" /> -->
      <el-table-column label="物料名称" align="center" prop="erpName" />
      <el-table-column label="规格" align="center" prop="chinaName" />
      <el-table-column label="物料编码" align="center" prop="partId" />
      
      <el-table-column label="物料类型" align="center" prop="mateType" >
        <template slot-scope="scope" >
          <dict-tag :options="dict.type.mate_type" :value="scope.row.mateType" />
        </template>
      </el-table-column>
      <el-table-column label="单位" align="center" prop="unit" />
      <!-- <el-table-column label="数量类型" align="center" prop="numType" >
        <template slot-scope="scope" >
          <dict-tag :options="dict.type.num_type" :value="scope.row.numType" />
        </template>
      </el-table-column> -->
      <el-table-column label="消耗数量" align="center" prop="mateNum" :formatter="matter"/>
      <el-table-column label="销售数量" align="center" prop="proNum" :formatter="matter"/>
      <el-table-column label="合计数量" align="center" prop="totalNum" :formatter="matter"/>
      <el-table-column label="期间" align="center" prop="periodDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.periodDate, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="别名" align="center" prop="asName" /> -->
      <!-- <el-table-column label="bom名称" align="center" prop="bomName" />
      <el-table-column label="bom版本" align="center" prop="bomVar" />
      <el-table-column label="父项编码" align="center" prop="parentId" />
      <el-table-column label="父项目版本" align="center" prop="fatherPartvar" />
      
      <el-table-column label="期间" align="center" prop="moth" />
      <el-table-column label="层次号" align="center" prop="assembLelevel" />
      <el-table-column label="物料版本" align="center" prop="partVar" />
      <el-table-column label="数量" align="center" prop="counts" />
      <el-table-column label="年度" align="center" prop="year" />
      <el-table-column label="市场价格" align="center" prop="marketPrice" />
      <el-table-column label="材料价格" align="center" prop="price" />
      <el-table-column label="含税单价" align="center" prop="taxPrice" />
      <el-table-column label="市场价格(含税)" align="center" prop="marktaxPrice" />
      <el-table-column label="成品价格" align="center" prop="productPrice" />
      <el-table-column label="直接人工" align="center" prop="workFee" />
      <el-table-column label="天然气" align="center" prop="gasFee" />
      <el-table-column label="电费" align="center" prop="elecFee" />
      <el-table-column label="制造费用" align="center" prop="makeFee" />
      <el-table-column label="标准合计" align="center" prop="stTotalFee" />
      <el-table-column label="合计" align="center" prop="totalFee" />
      <el-table-column label="毛利率" align="center" prop="grossProfitRate" />
      <el-table-column label="标准销售价格" align="center" prop="stSalePrice" />
      <el-table-column label="销售价格" align="center" prop="salePrice" /> -->
      <!-- <el-table-column label="时间戳" align="center" prop="nodeTimesTamp" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.nodeTimesTamp, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="价格时间" align="center" prop="priceTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.priceTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="marks" />
      <el-table-column label="基期" align="center" prop="partDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.partDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="root值" align="center" prop="rootCode" />
      <el-table-column label="序列号" align="center" prop="seqnum" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:count:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:count:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    
    <!-- <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    /> -->

    <!-- 添加或修改物料销售数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="物料名称" prop="chinaName">
          <el-input v-model="form.chinaName" placeholder="请输入物料名称" />
        </el-form-item>
        <el-form-item label="期间时间" prop="periodDate">
          <el-date-picker clearable
            v-model="form.periodDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择期间时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="消耗数量" prop="mateNum">
          <el-input v-model="form.mateNum" placeholder="请输入消耗数量" />
        </el-form-item>
        <el-form-item label="销售数量" prop="proNum">
          <el-input v-model="form.proNum" placeholder="请输入销售数量" />
        </el-form-item>
        <el-form-item label="合计数量" prop="totalNum">
          <el-input v-model="form.totalNum" placeholder="请输入合计数量" />
        </el-form-item>
        <el-form-item label="erp物料名称" prop="erpName">
          <el-input v-model="form.erpName" placeholder="请输入erp物料名称" />
        </el-form-item>
        <el-form-item label="别名" prop="asName">
          <el-input v-model="form.asName" placeholder="请输入别名" />
        </el-form-item>
        <el-form-item label="bom名称" prop="bomName">
          <el-input v-model="form.bomName" placeholder="请输入bom名称" />
        </el-form-item>
        <el-form-item label="bom版本" prop="bomVar">
          <el-input v-model="form.bomVar" placeholder="请输入bom版本" />
        </el-form-item>
        <el-form-item label="父项编码" prop="parentId">
          <el-input v-model="form.parentId" placeholder="请输入父项编码" />
        </el-form-item>
        <el-form-item label="父项目版本" prop="fatherPartvar">
          <el-input v-model="form.fatherPartvar" placeholder="请输入父项目版本" />
        </el-form-item>
        <el-form-item label="物料编码" prop="partId">
          <el-input v-model="form.partId" placeholder="请输入物料编码" />
        </el-form-item>
        <el-form-item label="期间" prop="moth">
          <el-input v-model="form.moth" placeholder="请输入期间" />
        </el-form-item>
        <el-form-item label="层次号" prop="assembLelevel">
          <el-input v-model="form.assembLelevel" placeholder="请输入层次号" />
        </el-form-item>
        <el-form-item label="物料版本" prop="partVar">
          <el-input v-model="form.partVar" placeholder="请输入物料版本" />
        </el-form-item>
        <el-form-item label="数量" prop="counts">
          <el-input v-model="form.counts" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="年度" prop="year">
          <el-input v-model="form.year" placeholder="请输入年度" />
        </el-form-item>
        <el-form-item label="市场价格" prop="marketPrice">
          <el-input v-model="form.marketPrice" placeholder="请输入市场价格" />
        </el-form-item>
        <el-form-item label="材料价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入材料价格" />
        </el-form-item>
        <el-form-item label="含税单价" prop="taxPrice">
          <el-input v-model="form.taxPrice" placeholder="请输入含税单价" />
        </el-form-item>
        <el-form-item label="市场价格(含税)" prop="marktaxPrice">
          <el-input v-model="form.marktaxPrice" placeholder="请输入市场价格(含税)" />
        </el-form-item>
        <el-form-item label="成品价格" prop="productPrice">
          <el-input v-model="form.productPrice" placeholder="请输入成品价格" />
        </el-form-item>
        <el-form-item label="直接人工" prop="workFee">
          <el-input v-model="form.workFee" placeholder="请输入直接人工" />
        </el-form-item>
        <el-form-item label="天然气" prop="gasFee">
          <el-input v-model="form.gasFee" placeholder="请输入天然气" />
        </el-form-item>
        <el-form-item label="电费" prop="elecFee">
          <el-input v-model="form.elecFee" placeholder="请输入电费" />
        </el-form-item>
        <el-form-item label="制造费用" prop="makeFee">
          <el-input v-model="form.makeFee" placeholder="请输入制造费用" />
        </el-form-item>
        <el-form-item label="标准合计" prop="stTotalFee">
          <el-input v-model="form.stTotalFee" placeholder="请输入标准合计" />
        </el-form-item>
        <el-form-item label="合计" prop="totalFee">
          <el-input v-model="form.totalFee" placeholder="请输入合计" />
        </el-form-item>
        <el-form-item label="毛利率" prop="grossProfitRate">
          <el-input v-model="form.grossProfitRate" placeholder="请输入毛利率" />
        </el-form-item>
        <el-form-item label="标准销售价格" prop="stSalePrice">
          <el-input v-model="form.stSalePrice" placeholder="请输入标准销售价格" />
        </el-form-item>
        <el-form-item label="销售价格" prop="salePrice">
          <el-input v-model="form.salePrice" placeholder="请输入销售价格" />
        </el-form-item>
        <el-form-item label="时间戳" prop="nodeTimesTamp">
          <el-date-picker clearable
            v-model="form.nodeTimesTamp"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择时间戳">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="价格时间" prop="priceTime">
          <el-date-picker clearable
            v-model="form.priceTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择价格时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="marks">
          <el-input v-model="form.marks" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="基期" prop="partDate">
          <el-date-picker clearable
            v-model="form.partDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择基期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="root值" prop="rootCode">
          <el-input v-model="form.rootCode" placeholder="请输入root值" />
        </el-form-item>
        <el-form-item label="序列号" prop="seqnum">
          <el-input v-model="form.seqnum" placeholder="请输入序列号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCount, getCount, delCount, addCount, updateCount } from "@/api/factory/materialxs/matectable";

export default {
  name: "Matectable",
  dicts: ['mtr_type','mate_type','num_type','sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料销售数据表格数据
      countList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: null,
        chinaName: null,
        periodDate: null,
        mateType: null,
        numType: null,
        mateNum: null,
        proNum: null,
        totalNum: null,
        erpName: null,
        asName: null,
        bomName: null,
        bomVar: null,
        parentId: null,
        fatherPartvar: null,
        partId: null,
        moth: null,
        assembLelevel: null,
        partVar: null,
        counts: null,
        year: null,
        marketPrice: null,
        price: null,
        taxPrice: null,
        marktaxPrice: null,
        productPrice: null,
        workFee: null,
        gasFee: null,
        elecFee: null,
        makeFee: null,
        stTotalFee: null,
        totalFee: null,
        grossProfitRate: null,
        stSalePrice: null,
        salePrice: null,
        nodeTimesTamp: null,
        priceTime: null,
        marks: null,
        partDate: null,
        rootCode: null,
        seqnum: null,
        flushi: 'N'
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        chinaName: [
          { required: true, message: "物料名称不能为空", trigger: "blur" }
        ],
        partId: [
          { required: true, message: "物料编码不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getNowTime();
    this.getList();
  },
  methods: {
    getNowTime() {
       var now = new Date();
       var year = now.getFullYear(); //得到年份
       var month = now.getMonth(); //得到月份
       var date = now.getDate(); //得到日期
      //  month = month + 1;
       month = month.toString().padStart(2, "0");
       date = date.toString().padStart(2, "0");
       var defaultDate = `${year}-${month}`;
      //  this.queryParams.periodDate=defaultDate
       this.$set(this.queryParams, "periodDate", defaultDate);
      //  return  defaultDate
      //  this.$set(this.queryParams, "periodDate", defaultDate);
   },
   indexMethod(index) {
     return index ;
   },

    // 添加千分符保留3为小数
    matter(row, column, cellValue) {
      if(null === cellValue) return '';
      cellValue += ''
      if (!cellValue.includes('.')) cellValue += '.'
      return parseFloat(cellValue).toFixed(8).replace(/(\d)(?=(\d{3})+\.)/g, function($0, $1) {
        return $1 + ','
      }).replace(/\.$/, '')
    },

    /** 查询物料销售数据列表 */
    getList() {
      this.loading = true;
      listCount(this.queryParams).then(response => {
        this.countList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        type: null,
        chinaName: null,
        periodDate: null,
        mateType: null,
        numType: null,
        mateNum: null,
        proNum: null,
        totalNum: null,
        erpName: null,
        asName: null,
        bomName: null,
        bomVar: null,
        parentId: null,
        fatherPartvar: null,
        partId: null,
        moth: null,
        assembLelevel: null,
        partVar: null,
        counts: null,
        year: null,
        marketPrice: null,
        price: null,
        taxPrice: null,
        marktaxPrice: null,
        productPrice: null,
        workFee: null,
        gasFee: null,
        elecFee: null,
        makeFee: null,
        stTotalFee: null,
        totalFee: null,
        grossProfitRate: null,
        stSalePrice: null,
        salePrice: null,
        nodeTimesTamp: null,
        priceTime: null,
        marks: null,
        createTime: null,
        updateTime: null,
        partDate: null,
        rootCode: null,
        seqnum: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加物料销售数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCount(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改物料销售数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCount(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCount(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除物料销售数据编号为"' + ids + '"的数据项？').then(function() {
        return delCount(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/count/export', {
        ...this.queryParams
      }, `销售数量列表_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
